package com.qyi.activemq.queue.producer;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author luqi
 * @Date 2021/3/11 10:07
 * @Description TODO
 */
@Service
@Slf4j
public class MqProducerService {

    @Autowired
    @Qualifier("templateP4")
    private JmsMessagingTemplate templateP4;

    @Autowired
    @Qualifier("templateP5")
    private JmsMessagingTemplate templateP5;

    @Autowired
    @Qualifier("templateP6")
    private JmsMessagingTemplate templateP6;

    @Autowired
    @Qualifier("templateNonPer")
    private JmsMessagingTemplate templateNonPer;

    @Autowired
    @Qualifier("templatePer")
    private JmsMessagingTemplate templatePer;

    @Autowired
    @Qualifier("templateAlive")
    private JmsMessagingTemplate templateAlive;

    public void sendQueue(String msg) {
        String finalMsg = msg + DateUtil.now();
        log.info("producer q3-queue-priority:{}", finalMsg);

        for (int i = 0; i < 5; i++) {
            templateP4.convertAndSend(new ActiveMQQueue("q3-queue-priority"), finalMsg + "-4");
            templateP5.convertAndSend(new ActiveMQQueue("q3-queue-priority"), finalMsg + "-5");
            templateP6.convertAndSend(new ActiveMQQueue("q3-queue-priority"), finalMsg + "-6");
        }
    }

    public void sendPer(String msg) {
        String finalMsg = msg + DateUtil.now();
        templatePer.convertAndSend(new ActiveMQQueue("q3-queue-Per"), finalMsg);
        templateNonPer.convertAndSend(new ActiveMQQueue("q3-queue-nonPer"), finalMsg);
        log.info("producer q3-queue-Per:{}", finalMsg);
    }

    public void sendAlive(String msg) {
        String finalMsg = msg + DateUtil.now();
        templateAlive.convertAndSend(new ActiveMQQueue("q3-queue-alive"), finalMsg);
        log.info("producer q3-queue-Alive:{}", finalMsg);
    }
}
